<template>
    <van-nav-bar title="评价" left-text="返回" left-arrow @click-left="onClickLeft" />

    <section class="aui-flexView">
        <!-- 订单详细 -->
        <section class="aui-scrollView">
            <!-- 订单状态 -->
            <div class="aui-pay-change">
                <div class="aui-flex">
                    <div class="aui-flex-box">
                        <h3>{{ orderInfo.status_text }}</h3>
                    </div>
                    <div class="aui-pay-zfb">
                        <img src="/assets/images/icon-zfb.png" alt="" />
                    </div>
                </div>
            </div>
            <!-- 订单商品 -->
            <div class="aui-commodity-bg">
                <div v-for="(product, index) in ProductList" :key="index" style="padding-bottom: 10px">
                    <div class="aui-flex">
                        <div class="aui-commodity-img">
                            <img @click="ToProduct(product.proid)" :data-proid="product.proid"
                                :src="product.products.cover_cdn" />
                        </div>
                        <div class="aui-flex-box">
                            <h4>{{ product.products.name }}</h4>
                            <p>商品单价：￥{{ product.price }}</p>
                            <span class="aui-barter-time">七天退换</span>
                        </div>
                        <div>
                            <h5>￥{{ product.total }}</h5>
                            <p class="aui-sml-text">X{{ product.pronum }}</p>
                        </div>
                    </div>
                    <div style="padding: 15px">
                        <van-rate v-model="product.rate" />
                    </div>
                    <div>
                        <van-cell-group inset>
                            <van-field v-model="product.comment" rows="2" autosize label="评价" type="textarea"
                                maxlength="150" placeholder="请输入评价" show-word-limit />
                        </van-cell-group>
                    </div>
                    <div style="padding: 15px">
                        <van-uploader v-model="product.imglist" :max-count="5" multiple 
                        :after-read="
                            (val) => {
                                afterRead(val, product.proid);
                            }
                        "
                        @delete="
                            (val) => {
                                afterDel(val, product.proid);
                            }"
                        />
                    </div>
                </div>
            </div>
        </section>
    </section>

    <div class="aui-flexView" style="width: 50%; margin-top: 10px;margin-bottom: 10px;">
        <van-button type="primary" @click="confirmrate()">确认评价</van-button>
    </div>
</template>
<script>
import { showNotify } from 'vant'
export default {
    data() {
        return {
            orderid: 0,
            LoginUser: this.$cookies.get('LoginAuth'),
            orderInfo: {},
            ProductList: [],
            RequestData:new FormData(),
            dataList: [],
        }
    },
    methods: {
        onClickLeft() {
            this.$router.go(-1)
        },
        async getInfoData() {
            let data = {
                orderid: this.orderid,
                busid: this.LoginUser.id
            }

            let result = await this.$api.OrderInfo(data)

            if (result.code === 0) {
                showNotify({
                    type: 'warning',
                    message: result.msg,
                    onClose: () => {
                        this.$router.go(-1)
                    }
                })

                return false
            }
            this.orderInfo = result.data
            this.ProductList = result.data.OrderProduct

            for(let item of this.ProductList)
            {
                this.dataList.push({
                    proid:item.proid
                })
            }

        },
        afterRead(file,proid)
        {
            if(file.length > 0)
            {
                file.forEach((item,index) => {
                    this.RequestData.append(proid + '[]',item.file)
                })
            }else{
                this.RequestData.append(proid + '[]',file.file)
            }
        },
        afterDel(file,proid)
        {
            const status = this.RequestData.getAll(proid + '[]')
            
            status.forEach((item,index) => {
                if(item == file.file)
                {
                    status.splice(index,1)
                    this.RequestData.delete(proid + '[]')
                }
            })

            status.forEach((item,index) => {
                this.RequestData.append(proid + '[]',item)
            })

        },
        async confirmrate()
        {
            for(let index in this.ProductList)
            {
                if(this.ProductList[index].rate > 0)
                {
                    this.dataList.forEach((item) => {
                        if(item.proid == this.ProductList[index].proid)
                        {
                            Object.assign(item,{
                                id:this.ProductList[index].id,
                                rate:this.ProductList[index].rate,
                                comment:this.ProductList[index].comment
                            })
                        }
                    })
                }else{
                    showNotify({
                        type: 'warning',
                        message: '评分不能为空',
                    })

                    return false
                }
            }
            
            this.RequestData.append('busid',this.LoginUser.id)

            this.RequestData.append('orderid',this.orderid)

            this.RequestData.append('data',JSON.stringify(this.dataList))

            let result = await this.$api.OrderRate(this.RequestData)

            if(result.code === 1)
            {
                showNotify({
                    type:'success',
                    message:result.msg,
                    onClose:() => {
                        this.$router.push('/user/order/index')
                    }
                })

                return false
            }else{
                showNotify({
                    type:'warning',
                    message:result.msg
                })

                return false
            }

        }
    },
    created() {
        this.orderid = this.$route.query.orderid ? this.$route.query.orderid : 0;
        this.getInfoData()
    },
}
</script>

<style scoped>
.divHeight {
    width: 100%;
    height: 10px;
    background: #f5f5f5;
    position: relative;
    /* overflow: hidden; */
}

.r-line {
    position: relative;
}

.r-line:after {
    content: "";
    position: absolute;
    z-index: 0;
    top: 0;
    right: 0;
    height: 100%;
    border-right: 1px solid #d9d9d9;
    -webkit-transform: scaleX(0.5);
    transform: scaleX(0.5);
    -webkit-transform-origin: 100% 0;
    transform-origin: 100% 0;
}

.b-line {
    position: relative;
}

.b-line:after {
    content: "";
    position: absolute;
    z-index: 2;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 1px;
    border-bottom: 1px solid #e2e2e2;
    -webkit-transform: scaleY(0.5);
    transform: scaleY(0.5);
    -webkit-transform-origin: 0 100%;
    transform-origin: 0 100%;
}

.aui-flex {
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    align-items: center;
    padding: 15px;
    position: relative;
}

.aui-flex-box {
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    flex: 1;
    min-width: 0;
    font-size: 13px;
    color: #333;
    /* width: 100%; */
}

/* 必要布局样式css */
.aui-flexView {
    width: 100%;
    height: 100%;
    margin: 0 auto;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -webkit-flex-direction: column;
    -ms-flex-direction: column;
    flex-direction: column;
}

.aui-scrollView {
    width: 100%;
    height: 100%;
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    -ms-flex: 1;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    position: relative;
    margin-top: 0;
}

.aui-navBar {
    height: 44px;
    position: relative;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    z-index: 1002;
    background: #f7f6f6;
}

.aui-navBar-item {
    height: 44px;
    min-width: 35%;
    -webkit-box-flex: 0;
    -webkit-flex: 0 0 35%;
    -ms-flex: 0 0 35%;
    flex: 0 0 35%;
    padding: 0 0.9rem;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    font-size: 0.7rem;
    white-space: nowrap;
    overflow: hidden;
    color: #353535;
    position: relative;
}

.aui-navBar-item:first-child {
    -webkit-box-ordinal-group: 2;
    -webkit-order: 1;
    -ms-flex-order: 1;
    order: 1;
    margin-right: -25%;
    font-size: 0.9rem;
    font-weight: bold;
    color: #717171;
}

.aui-navBar-item:last-child {
    -webkit-box-ordinal-group: 4;
    -webkit-order: 3;
    -ms-flex-order: 3;
    order: 3;
    -webkit-box-pack: end;
    -webkit-justify-content: flex-end;
    -ms-flex-pack: end;
    justify-content: flex-end;
}

.aui-center {
    -webkit-box-ordinal-group: 3;
    -webkit-order: 2;
    -ms-flex-order: 2;
    order: 2;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    -ms-flex-pack: center;
    justify-content: center;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    height: 44px;
    width: 50%;
    margin-left: 25%;
}

.aui-center-title {
    text-align: center;
    width: 100%;
    white-space: nowrap;
    overflow: hidden;
    display: block;
    text-overflow: ellipsis;
    font-size: 0.95rem;
    color: #333;
}

.icon {
    width: 20px;
    height: 20px;
    display: block;
    border: none;
    float: left;
    background-size: 20px;
    background-repeat: no-repeat;
}

.icon-return {
    background-image: url("");
}

.icon-more {
    background-image: url("");
}

.aui-pay-change {
    /* height: 120px; */
    background-image: -webkit-gradient(linear,
            left top,
            right top,
            from(#ff9000),
            to(#ff5101));
    background-image: -webkit-linear-gradient(left, #ff9000, #ff5101);
    background-image: -moz-linear-gradient(left, #ff9000, #ff5101);
    background-image: linear-gradient(to right, #ff9000, #ff5101);
    background-color: #ff5101;
    /* margin-bottom: 20px; */
}

.aui-pay-zfb {
    width: 100px;
}

.aui-pay-zfb img {
    width: 100%;
    height: auto;
    display: block;
    border: none;
}

.aui-pay-change .aui-flex {
    padding: 20px 30px;
    color: #fff;
}

.aui-pay-change .aui-flex-box {
    color: #fff;
}

.aui-flex-add {
    width: 40px;
    height: 40px;
    margin-right: 10px;
}

.aui-flex-add img {
    width: 100%;
    height: auto;
    display: block;
    border: none;
}

.aui-flex-box h3 {
    /* padding-bottom:10px; */
}

.aui-flex-box h3 em {
    font-size: 14px;
    color: #999;
    font-style: normal;
    font-weight: normal;
}

.aui-shop-item {
    width: 25px;
    height: 25px;
    margin-right: 5px;
}

.aui-shop-item img {
    width: 100%;
    height: auto;
    display: block;
    border: none;
}

.aui-shop-item-arrow {
    position: relative;
    font-size: 14px;
    color: #333;
}

.aui-shop-item-arrow:after {
    content: " ";
    display: inline-block;
    height: 8px;
    width: 8px;
    border-width: 2px 2px 0 0;
    border-color: #949494;
    border-style: solid;
    -webkit-transform: matrix(0.71, 0.71, -0.71, 0.71, 0, 0);
    transform: matrix(0.71, 0.71, -0.71, 0.71, 0, 0);
    position: relative;
    top: -2px;
    position: absolute;
    top: 50%;
    margin-top: -4px;
    right: -13px;
    border-radius: 1px;
}

.aui-commodity-bg {
    background: #f5f5f5;
}

.aui-commodity-img {
    width: 85px;
    height: 85px;
    margin-right: 5px;
}

.aui-commodity-img img {
    width: 100%;
    height: auto;
    display: block;
    border: none;
}

.aui-barter-time {
    border: 1px solid #ff5306;
    color: #ff5306;
    font-size: 13px;
    border-radius: 3px;
    background: #fff1ec;
    padding: 2px 5px;
}

.aui-commodity-bg .aui-flex {
    -webkit-box-align: initial;
    -webkit-align-items: initial;
    align-items: initial;
}

.aui-flex-box p {
    font-size: 12px;
    color: #999;
    padding: 5px 0;
}

.aui-pay-change .aui-flex-box p {
    color: #fff;
}

.aui-insurance-img {
    width: 25px;
    height: 25px;
    margin-right: 5px;
}

.aui-insurance-img img {
    width: 100%;
    height: auto;
    display: block;
    border: none;
}

.aui-insurance-box .aui-flex-box h5 {
    color: #999999;
}

.aui-sml-text {
    font-size: 12px;
    padding-top: 5px;
}

.aui-flex-ed em {
    float: right;
    font-style: normal;
    color: #999999;
}

.aui-cp-edu {
    position: relative;
    padding: 10px 15px;
}

.aui-cp-edu .aui-flex {
    padding: 2px 0;
    color: #999;
}

.aui-cp-edu .aui-flex-box {
    color: #999;
}

.aui-san-sml {
    position: absolute;
    bottom: 0;
    right: 27px;
    width: 0;
    border-right: 10px solid transparent;
    border-left: 10px solid transparent;
    border-bottom: 10px solid #e5e5e5;
}

.aui-flex-text-sml p {
    color: #666666;
    font-size: 12px;
}

.aui-flex-text-sml p em {
    font-style: normal;
    padding-right: 5px;
}

.aui-btn-copy {
    border: 1px solid #ddd;
    font-size: 12px;
    padding: 2px 10px;
    border-radius: 2px;
}

.aui-confirm-flex {
    position: relative;
    line-height: 40px;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
}

.aui-confirm-flex .aui-modify-btn {
    position: relative;
    text-align: center;
    display: block;
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    -ms-flex: 1;
    flex: 1;
    padding: 0 2px;
    font-size: 0.8rem;
    color: #191919;
    height: 45px;
    line-height: 45px;
}

.aui-confirm-flex>a:not(:last-child):after {
    content: "";
    position: absolute;
    z-index: 0;
    top: 10px;
    right: 0;
    height: 50%;
    border-right: 1px solid #b3b3b3;
    -webkit-transform: scaleX(0.5);
    transform: scaleX(0.5);
    -webkit-transform-origin: 100% 0;
    transform-origin: 100% 0;
}

.icon-kf {
    top: 13px;
    left: 40px;
    position: absolute;
    background-image: url("");
}

.icon-dh {
    position: absolute;
    background-image: url("");
    top: 13px;
    left: 40px;
}

.aui-like {
    width: 100%;
}

.aui-like img {
    width: 100%;
    height: auto;
    display: block;
    border: none;
}

/* shop list */
.aui-shop-list {
    position: relative;
    overflow: hidden;
    padding-left: 10px;
    background: #f2f2f2;
    padding-bottom: 50px;
}

.aui-shop-list-item {
    width: 48%;
    float: left;
    position: relative;
    z-index: 0;
    /* padding: 0.32rem 0; */
    font-size: 0.28rem;
    margin-right: 2%;
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 10px;
}

.aui-shop-list-item-hd {
    position: relative;
}

.aui-shop-list-item-hd img {
    width: 100%;
    height: auto;
    display: block;
    border: none;
}

.aui-shop-list-item-bd {
    text-align: center;
    font-size: 0.9rem;
    color: #333;
    padding: 10px;
    font-weight: bold;
}

.aui-shop-list-selected .aui-shop-list-item h3 {
    color: #333;
    font-size: 0.8rem;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    font-weight: normal;
    text-align: left;
    margin-top: 0;
    margin-bottom: 0.5rem;
}

.aui-shop-list-selected .aui-special-text {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
    font-weight: normal;
}

.aui-shop-list-selected .aui-special-etc {
    color: #ff5000;
    font-weight: inherit;
    /* padding-top: 10px; */
    font-size: 16px;
    text-align: left;
}

.aui-shop-list-selected .aui-special-etc .aui-special-etc-bd {
    text-decoration: line-through;
    color: #999;
    font-weight: normal;
    font-size: 0.7rem;
}

.aui-shop-list-selected .aui-special-text em {
    color: #eb2745;
    font-size: 0.65rem;
    border-radius: 20px;
    border: 1px solid #eb2745;
    font-style: normal;
    padding: 0 0.4rem;
    margin-right: 2px;
}

.aui-shop-list-selected .aui-special-text span {
    color: #999;
    font-weight: normal;
    font-size: 0.65rem;
}

.aui-footer {
    width: 100%;
    position: relative;
    z-index: 100;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    padding: 7px 5px 7px 5px;
    background: #ffffff;
}

.aui-footer:after {
    content: "";
    position: absolute;
    z-index: 0;
    top: 0;
    left: 0;
    width: 100%;
    height: 1px;
    border-top: 1px solid #bbbbbb;
    -webkit-transform: scaleY(0.5);
    transform: scaleY(0.5);
    -webkit-transform-origin: 0 100%;
    transform-origin: 0 100%;
}

.aui-tabBar-item {
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    -ms-flex: 1;
    flex: 1;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -webkit-flex-direction: column;
    -ms-flex-direction: column;
    flex-direction: column;
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    -ms-flex-pack: center;
    justify-content: center;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    color: #979797;
}

.aui-tabBar-item-text {
    display: inline-block;
    font-size: 0.65rem;
    color: #757980;
    padding-top: 2px;
}

.aui-tabBar-item-active .aui-tabBar-item-text {
    color: #fe3542;
}

.aui-footer-fixed {
    position: fixed;
    bottom: 0;
    left: 0;
    z-index: 49;
}

.aui-footer-text-info {
    width: 100%;
    text-align: right;
    padding: 10px 0;
}

.aui-footer-text-info a {
    border: 1px solid #d6d6d6;
    color: #666666;
    font-size: 12px;
    border-radius: 20px;
    padding: 3px 10px;
    margin: 0 4px;
}

.aui-footer-text-info .aui-payment {
    border-color: #ff5500;
    color: #ff5500;
}

.aui-special-etc em {
    float: right;
}

.icon-sm-more {
    background-image: url("");
}

.orderinfo {
    padding-bottom: 5em;
}
</style>